package com.zmn.oms.common.constant;

import com.zmn.common.constant.GlobalConsts;
import lombok.Data;

import java.util.Objects;

/**
 * 类描述：师傅按单保险常量
 *
 * @author lhl
 * @date 2020/06/01 15:53
 */
public final class InsConsts {

    private static final int CATEG_ONE_ID_AC = 1000;    // 一级分类-空调
    private static final int CATEG_ONE_ID_HEATER = 2404;    // 一级分类-热水器
    private static final int CATEG_ID_SOLAR_HEATER = 2559;  // 二级分类-太阳能热水器

    /**
     * 产品品类标签
     */
    public static final int CATEG_TAG_OTHER = 0;
    public static final int CATEG_TAG_AC_REPAIR = 201;  // 空调维修
    public static final int CATEG_TAG_AC_INSTALL = 301; // 空调安装
    public static final int CATEG_TAG_SOLAR_HEATER_REPAIR = 202;  // 太阳能热水器维修
    public static final int CATEG_TAG_SOLAR_HEATER_INSTALL = 302; // 太阳能热水器安装

    /**
     * 计价级别
     */
    public static final int PRICE_LV1 = 1;  // 0.2元
    public static final int PRICE_LV2 = 2;  // 0.8元

    /**
     * 保险消息队列tag
     */
    public static final String MQ_TAG_MASTER_INSURANCE = "engineer_insurance";    // 师傅保险
    public static final String MQ_TAG_ORDER_MAIN_MASTER = "engineer_insurance_valid_order";  // 订单有效师傅

    /**
     * 伪常量
     */
    public static String CPIC_SYNC_KEY;
    public static String CPIC_SYNC_URL;

    public static String CPIC_INSURE_APPID;
    public static String CPIC_INSURE_SECRETKEY;
    public static String CPIC_INSURE_URL;
    public static String CPIC_INSURE_CALLBACK_URL;

    public static Integer MSG_RULE_ID;
    public static String DINGTALK_ID_FOR_RECIVE_MSG;

    public static String ZMN_TOPIC_ENGINEER;


    /**
     * 获取订单的保险级别
     * @param servCategId
     * @param categOneId
     * @param categId
     * @return
     */
    public static InsOrderLevel getInsOrderLevel(Integer servCategId, Integer categOneId, Integer categId) {
        do {
            boolean isRepair = Objects.equals(GlobalConsts.SERV_CATEG_REPAIR, servCategId);
            boolean isInstall = Objects.equals(GlobalConsts.SERV_CATEG_INSTALL, servCategId);

            // 非维修/安装类型，按普通保险单处理
            if (!isRepair && !isInstall) {
                break;
            }

            // 空调（使用一级分类ID判断）
            if (Objects.equals(CATEG_ONE_ID_AC, categOneId)) {
                if (isRepair) {
                    return new InsOrderLevel("空调维修", CATEG_TAG_AC_REPAIR , PRICE_LV2);
                }
                else {
                    return new InsOrderLevel("空调安装", CATEG_TAG_AC_INSTALL , PRICE_LV2);
                }
            }
            // 太阳能热水器（使用二级分类ID判断）
            else if (Objects.equals(CATEG_ID_SOLAR_HEATER, categId)) {
                if (isRepair) {
                    return new InsOrderLevel("太阳能热水器维修", CATEG_TAG_SOLAR_HEATER_REPAIR , PRICE_LV2);
                }
                else {
                    return new InsOrderLevel("太阳能热水器安装", CATEG_TAG_SOLAR_HEATER_INSTALL , PRICE_LV2);
                }
            }
        } while (false);

        return new InsOrderLevel("其他", CATEG_TAG_OTHER, PRICE_LV1);
    }

    /**
     * 私有构造器，防止外部实例化
     */
    private InsConsts () {}

    /**
     * 保险订单级别属性
     */
    @Data
    public static class InsOrderLevel {
        /**
         * 产品品类名称
         */
        private String categName;
        /**
         * 产品品类标签
         */
        private int categTag;
        /**
         * 计价级别
         */
        private int priceLevel;

        public InsOrderLevel(String categName, int categTag, int priceLevel) {
            this.categName = categName;
            this.categTag = categTag;
            this.priceLevel = priceLevel;
        }
    }
}
